<template>
  <el-card>
    <el-form inline>
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.c1Id"
          style="width: 240px"
          @change="handler"
          :disabled="scene == 0 ? false : true"
        >
          <!-- label:即为展示数据 value:即为select下拉菜单收集的数据 -->
          <el-option
            v-for="(c1, index) in categoryStore.c1Arr"
            :key="index"
            :label="c1.name"
            :value="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          style="width: 240px"
          v-model="categoryStore.c2Id"
          @change="handler1"
          :disabled="scene == 0 ? false : true"
        >
          <el-option
            :label="c2.name"
            v-for="(c2, index) in categoryStore.c2Arr"
            :key="index"
            :value="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          :disabled="scene == 0 ? false : true"
          style="width: 240px"
          v-model="categoryStore.c3Id"
        >
          <el-option
            :label="c3.name"
            v-for="(c3, index) in categoryStore.c3Arr"
            :key="index"
            :value="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>
  
  <script setup lang="ts">
//引入组件挂载完毕方法
import { onMounted, defineProps } from "vue";

//引入分类相关的仓库
import useCategoryStore from "@/store/modules/Category";
let categoryStore = useCategoryStore();
//分类全局组件挂载完毕,通知仓库发请求获取一级分类的数据
onMounted(() => {
  getC1();
});

//通知仓库获取一级分类的方法
const getC1 = () => {
  //通知分类仓库发请求获取一级分类的数据
  categoryStore.getC1();
};

//此方法即为一级分类下拉菜单的change事件(选中值的时候会触发,保证一级分类ID有了)
const handler = () => {
  //需要将二级、三级分类的数据清空
  categoryStore.c2Id = "";
  categoryStore.c3Arr = [];
  categoryStore.c3Id = "";
  //通知仓库获取二级分类的数据
  categoryStore.getC2();
};

const handler1 = () => {
  categoryStore.c3Id = "";
  //通知仓库获取二级分类的数据
  categoryStore.getC3();
};

// 接受父组件船只
defineProps(["scene"]);
</script>
  
  <style lang="" scoped></style>
  